/*
 * @lc app=leetcode.cn id=1013 lang=javascript
 *
 * [1013] 将数组分成和相等的三个部分
 */

// @lc code=start
/**
 * @param {number[]} A
 * @return {boolean}
 */
var canThreePartsEqualSum = function(A) {
    let sum=A.reduce((a,b)=>a+b)/3
    if(sum%1!=0)return false
    let i=0,j=A.length-1
    let sum1=0,sum2=0
    while(i<A.length-2){
        sum1+=A[i]
        i++
        if(sum1==sum)break
    }
    if(sum1!=sum)return false
    while(j>i){
        sum2+=A[j]
        j--
        if(sum2==sum)break
    }
    if(sum2!=sum)return false
    return true
};
// @lc code=end

